package cn.iocoder.yudao.module.member.service.faceanalyseresult;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.member.controller.admin.faceanalyseresult.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.faceanalyseresult.FaceanalyseResultDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.member.dal.mysql.faceanalyseresult.FaceanalyseResultMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;

/**
 * 会员皮肤状态分析结果 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class FaceanalyseResultServiceImpl implements FaceanalyseResultService {

    @Resource
    private FaceanalyseResultMapper faceanalyseResultMapper;

    @Override
    public Long createFaceanalyseResult(FaceanalyseResultSaveReqVO createReqVO) {
        // 插入
        FaceanalyseResultDO faceanalyseResult = BeanUtils.toBean(createReqVO, FaceanalyseResultDO.class);
        faceanalyseResultMapper.insert(faceanalyseResult);

        // 返回
        return faceanalyseResult.getId();
    }

    @Override
    public void updateFaceanalyseResult(FaceanalyseResultSaveReqVO updateReqVO) {
        // 校验存在
        validateFaceanalyseResultExists(updateReqVO.getId());
        // 更新
        FaceanalyseResultDO updateObj = BeanUtils.toBean(updateReqVO, FaceanalyseResultDO.class);
        faceanalyseResultMapper.updateById(updateObj);
    }

    @Override
    public void deleteFaceanalyseResult(Long id) {
        // 校验存在
        validateFaceanalyseResultExists(id);
        // 删除
        faceanalyseResultMapper.deleteById(id);
    }

    @Override
        public void deleteFaceanalyseResultListByIds(List<Long> ids) {
        // 删除
        faceanalyseResultMapper.deleteByIds(ids);
        }


    private void validateFaceanalyseResultExists(Long id) {
        if (faceanalyseResultMapper.selectById(id) == null) {
            throw exception(FACEANALYSE_RESULT_NOT_EXISTS);
        }
    }

    @Override
    public FaceanalyseResultDO getFaceanalyseResult(Long id) {
        return faceanalyseResultMapper.selectById(id);
    }

    @Override
    public PageResult<FaceanalyseResultRespVO> getFaceanalyseResultPage(FaceanalyseResultPageReqVO pageReqVO) {
        return faceanalyseResultMapper.selectPage(pageReqVO);
    }

}